/* $RCSFile: ADNDynAnnouncement.cs $
 * Apache license v2 2011 by Christian Surieux
 * $Source: ?/CRMWrapper3/DynEntities/ADNDynAnnouncement.cs $
 * $log$
 * Revision 19 2010/10/02 14:01:48  christian.surieux
 *   Corrected a bug in allmost everyADNDyn file for PrimaryFieldVualue
 * Revision 6 2010/08/06 19:56:32  christian.surieux
 *   Added Log to All cs files
 */

using System;
using System.Diagnostics;
using System.Collections;
using System.ComponentModel;
using System.Collections.Generic;
using System.Text;
using System.Data;

using CrmSdk;

namespace AddonNice.CRMWrapper
{
	public class ADNDynAnnouncement : DynEntity
	{
        protected class Ftor: DFactor
        {
            public Ftor() : base(CrmStr.businessunitnewsarticle)
            {}

            public override Type DynType
            { get { return typeof(ADNDynAnnouncement); } }

            public override string DynTypename
            {   get{ return CrmStr.businessunitnewsarticle;}}

            public override DynEntity Build()
            {   return new ADNDynAnnouncement();}

            public override DynEntity Build(CRMWrapperBase w, InternalDynamicEntity dEntity, PropertyDescriptorCollection wproperties)
            {   return new ADNDynAnnouncement(w, dEntity, wproperties, null);}

            public override DynEntity Build(CRMWrapperBase w, string PrimaryFieldValue)
            {   return new ADNDynAnnouncement(w,PrimaryFieldValue);}

            public override DynEntity Build(CRMWrapperBase w,Guid PrimaryKeyValue)
            {   return new ADNDynAnnouncement(w,PrimaryKeyValue);}
        }

        static ADNDynAnnouncement(){new Ftor();} 

        public override bool HasOwnerProperty
        {
            get
            {
                return false;
            }
        }

        public override bool HasBusinessUnitProperty
        {
            get
            {
                return false;
            }
        }

        public override bool HasOwningBusinessUnitProperty
        {
            get
            {
                return false;
            }
        }

        public ADNDynAnnouncement(): base()
		{}

        public ADNDynAnnouncement(CRMWrapperBase w, string PrimaryFiedlValue)
			: base(w, CrmStr.businessunitnewsarticle)
		{
            if ( PrimaryFiedlValue != string.Empty )
                articletitle    =   PrimaryFiedlValue;
		}

		public ADNDynAnnouncement(CRMWrapperBase w, Guid CrmId)
			: base(w,CrmStr.businessunitnewsarticle, CrmId)
		{}

		public ADNDynAnnouncement(CRMWrapperBase w, InternalDynamicEntity e)
			: base(w,CrmStr.businessunitnewsarticle,e,null,null)
		{}

		public ADNDynAnnouncement(CRMWrapperBase w, InternalDynamicEntity e,PropertyDescriptorCollection prop,InternalColumnSet s)
			: base(w,CrmStr.businessunitnewsarticle,e,prop,s)
		{}

        public ADNDynAnnouncement(ResetWrapperHandler fn, string PrimaryFiedlValue)
			: base(fn, CrmStr.businessunitnewsarticle)
		{
            if ( PrimaryFiedlValue != string.Empty )
                articletitle    =   PrimaryFiedlValue;
		}

		public ADNDynAnnouncement(ResetWrapperHandler fn, Guid CrmId)
			: base(fn,CrmStr.businessunitnewsarticle, CrmId)
		{}

		public ADNDynAnnouncement(ResetWrapperHandler fn, InternalDynamicEntity e)
			: base(fn,CrmStr.businessunitnewsarticle,e,null,null)
		{}

		public ADNDynAnnouncement(ResetWrapperHandler fn, InternalDynamicEntity e,PropertyDescriptorCollection prop,InternalColumnSet s)
			: base(fn,CrmStr.businessunitnewsarticle,e,prop,s)
		{}

		/// <summary>
		/// Crm Key
		/// </summary>
        [CrmDynAttribute(CrmStr.businessunitnewsarticle)]
        public Guid businessunitnewsarticleid
		{
			get
			{
				return KeyPropertyValue(CrmStr.businessunitnewsarticleid);
			}
			set
			{
				AddKeyProperty(CrmStr.businessunitnewsarticleid, value);
			}
		}

        protected override void SetCrmIdProperty(Guid crmId)
        {
           if ( !dicProperty.ContainsKey(CrmStr.businessunitnewsarticleid) || KeyPropertyValue(CrmStr.businessunitnewsarticleid) != crmId )
                businessunitnewsarticleid   =   crmId;
        }
        
        public override string PrimaryFieldName
        {
            get
            {
               return CrmStr.articletitle;
            }
           set
           {}
        }

        public override string PrimaryFieldStringValue
        {
            get
            {
                return articletitle;
            }
            set
            {
                articletitle =   value;
            }
        }

        public override Guid PrimaryKeyGuidValue
        {
           get
           {
                return businessunitnewsarticleid;
           }
           set
           {
               businessunitnewsarticleid    =   value;
           }
        }

        /// <summary>
        /// Gets or sets the title of the announcement
        /// </summary>
        [CrmDynAttribute(CrmStr.businessunitnewsarticle)]
        public string articletitle 
        {
            get
            {
                return StringPropertyValue(CrmStr.articletitle);
            }
            set
            {
                AddStringProperty(CrmStr.articletitle,value);
            }
        }

        /// <summary>
        /// Gets or sets the URL for the Web site on which the announcement is located.
        /// </summary>
        [CrmDynAttribute(CrmStr.businessunitnewsarticle)]
        public string articleurl 
        {
            get
            {
                return StringPropertyValue(CrmStr.articleurl);
            }
            set
            {
                AddStringProperty(CrmStr.articleurl,value);
            }
        }
        
        /// <summary>
        /// Gets or sets the text for the announcement.
        /// </summary>
        [CrmDynAttribute(CrmStr.businessunitnewsarticle)]
        public string newsarticle 
        {
            get
            {
                return StringPropertyValue(CrmStr.newsarticle);
            }
            set
            {
                AddStringProperty(CrmStr.newsarticle,value);
            }
        }

        /// <summary>
        /// All Users, Sales Users, Service Users
        /// </summary>
        [CrmDynAttribute(CrmStr.businessunitnewsarticle)]
        public int articletypecode
        {
            get
            {
                return PicklistPropertyIntValue(CrmStr.articletypecode);
            }
            set
            {
                AddPicklistProperty(CrmStr.articletypecode,value);
            }
        }

        public string articletypecodeLabel
        {
            get
            {
                return PicklistPropertyLabelValue(CrmStr.articletypecode);
            }
        }

        [CrmDynAttribute(CrmStr.businessunitnewsarticle)]
        public string activeon
        {
            get
            {
                return DateTimePropertyValue(CrmStr.activeon);
            }
        }

        public DateTime activeonUTCDate
        {
            get
            {
                return DateTimePropertyDate(CrmStr.activeon,false);
            }
        }

        public DateTime activeonLocalDate
        {
            get
            {
                return DateTimePropertyDate(CrmStr.activeon,true);
            }
        }
    
        [CrmDynAttribute(CrmStr.businessunitnewsarticle)]
        public string activeuntil
        {
            get
            {
                return DateTimePropertyValue(CrmStr.activeuntil);
            }
        }

        public DateTime activeuntilUTCDate
        {
            get
            {
                return DateTimePropertyDate(CrmStr.activeuntil,false);
            }
        }

        public DateTime activeuntilLocalDate
        {
            get
            {
                return DateTimePropertyDate(CrmStr.activeuntil,true);
            }
        }

        [CrmDynAttribute(CrmStr.businessunitnewsarticle)]
        public bool showonhomepage
        {
            get 
            {
                return BooleanPropertyValue(CrmStr.showonhomepage);
            }
            set 
            {
                AddBooleanProperty(CrmStr.showonhomepage,value);
            }
        }

        public static void PrepareAnnouncements(CRMWrapperBase Wrapper,ResetWrapperHandler rfn,DynamicEntityDelegate fn)
        {
                GenericDynQueryMultiple<ADNDynAnnouncement> allEntQuery      =   new GenericDynQueryMultiple<ADNDynAnnouncement>(Wrapper,rfn,CrmStr.businessunitnewsarticle);
                InternalQueryExpression qe                          =   null;
                // We don't need addresses already created with accounts or contacts
                    DateTime startdate                              =   DateTime.Now;
                    qe                                              =   new InternalQueryExpression();
                    qe.EntityName                                   =   CrmStr.businessunitnewsarticle;
                    InternalAllColumns RequestCols                  =   new InternalAllColumns();
                    InternalFilterExpression fi                     =   new InternalFilterExpression();
                    InternalConditionExpression ex                  =   new InternalConditionExpression();
                    ex.AttributeName                                =   CrmStr.activeuntil;
                    ex.Operator                                     =   InternalConditionOperator.OnOrAfter;
                    ex.Values                                       =   new string[]{startdate.ToShortTimeString()};
                    fi.Conditions                                   =   new InternalConditionExpression[]{ex};
                    qe.ColumnSet                                    =   RequestCols;
                    qe.Criteria                                     =   fi;

                // Retrieve all
                InternalBusinessEntityCollection allEnt             =   allEntQuery.adminRetrieve(qe);
                // Do the insert command on each item
                Wrapper.Util.ExecForEachDynamicEntity(allEnt,fn);
        }

    }
}
